// pages/perfectData/perfectData.js
const app = getApp()
var CONFIG = require("../../config/config.js");
var share = require("../../utils/share.js");
var list = [];
Page({

    /**
     * 页面的初始数据
     */
    data: {
        is_exam:0, //是否通过考试
        identity:1,
        is_dl:0,
        adminid:'',
        is_lz:0,//0禁用 1正常
        newlearnid: '', //学管师id
        newconid: '',//课程顾问id
        tyepsub:'',
        is_certif: 0, //是否认证 0:需要认证 1:无需已认证
        is_check: 0, //是否可以被选走 0:不可以 1:可以
        is_cons: 0, //是否有课程顾问 0:没有课程顾问 1:有课程顾问
        is_status:0,  //0未成交 1已成交 
        is_oneself:0, //0-不在自己名下 1-自己名下
        typestatus:1,  //1添加 2编辑
        isname: 1, //是否可以修改名字 is_name：  1-可以 2-不可以
        share_conid:0,
        is_learn:0, //1学管师
        region: ['', ''],
        index: 0,
        userSex: 1,
        consultant_id:'',
        multiIndex: [0, 0],
        multiArray: [],
        objectMultiArray: [],
        submitfalse:true,
        userInclist:[],  //意向等级
        inc_index:0, //意向等级下标
        name:'请选择',
        provinceslist:[],
        chooselist:[],
        dataedit:{},
        addlist:[],
        valueadd:[],
        pickitem: '',
        pickindex:'',
        choosefalse:false,
        morekinfo:[],
        moreindex:[],
        yi_status:0,
        photo:'',
        imgUrl:CONFIG.API_PIC,
        is_dl: Number(app.globalData.is_dl)
    },
    telblurtel(e){
        var that = this;
        var tel = e.detail.value;
        if ((/^1\d{10}$/.test(tel))) {
            var obj = {
                phone: tel,
                consultant_id: that.data.consultant_id,   //课程顾问id
            }
            share.wxRequest('crmapi/user/entryStuInfoNew', obj, function (res) {
                if (Number(res.data.errcode) == 0) {
                    var data = res.data.data.res;
                    that.setData({
                        is_certif: data.is_certif, //是否认证 0:需要认证 1:无需已认证
                        is_check: Number(data.is_check), //是否可以被选走 0:不可以 1:可以
                        is_cons: data.is_cons, //是否有课程顾问 0:没有课程顾问 1:有课程顾问 2代理商
                        is_learn:data.is_learn, //1学管
                        is_lz:Number(data.is_status),
                        newconid: Number(data.consultant_id),
                        newlearnid: Number(data.learn_id),
                        share_conid:0,
                        is_oneself:Number(data.is_oneself),
                        dataedit: {
                            phone:tel,
                        }
                    })
                    if(Number(data.consultant_id)>0){
                        var share_conid = data.consultant_id;
                    }else if(Number(data.learn_id)>0){
                        var share_conid = data.learn_id;
                    }else{
                        var share_conid = 0;
                    }
                    that.setData({
                        share_conid:share_conid
                    })
                    if (data.userInfo.phone){
                        if (Number(data.userInfo.sex)<=0){
                            var sex = 1;
                        }else{
                            var sex = data.userInfo.sex;
                        }
                        // console.log(8999)
                        that.setData({
                            dataedit: data.userInfo,
                            userSex: sex,
                            region: ['', ''],
                            // region: [data.userInfo.provinces_name, data.userInfo.city_name], 
                            is_status:data.userInfo.status
                        })
                        that.datainfo1(data.userInfo);
                        // that.datainfo(data.userInfo);
                    }
                    // console.log(that.data.dataedit);
                }else{
                    wx.showToast({
                        title: res.data.msg,
                        icon: 'none',
                        duration: 1500
                    })
                    that.setData({
                        dataedit: {
                            phone: '',
                        },
                        is_certif: 0, //是否认证 0:需要认证 1:无需已认证
                        is_check: 0, //是否可以被选走 0:不可以 1:可以
                        is_cons: 0, //是否有课程顾问 0:没有课程顾问 1:有课程顾问
                        is_learn:0,
                    })
                }
            })
        }else{
            console.log(e);
            that.setData({
                is_certif: 0, //是否认证 0:需要认证 1:无需已认证
                is_check: 0, //是否可以被选走 0:不可以 1:可以
                is_cons: 0, //是否有课程顾问 0:没有课程顾问 1:有课程顾问
                is_learn:0,
                dataedit: {
                    phone: tel,
                },
            })
        }
    },
    focusbind(e) {
        var that = this;
        var pickindex = that.data.pickindex;
        // console.log(e);
        // console.log(pickindex);
        var value = e.detail.value;
        var addlist = that.data.addlist;
        addlist[pickindex].valueadd = value;
    },
    listchange(e){
        var that = this;
        // console.log(e);
        var pickindex = that.data.pickindex;
        var index = e.detail.value;
        var addlist = that.data.addlist;
        addlist[pickindex].evalue = index;
        addlist[pickindex].valueadd = that.data.pickitem.input_values[index].edesc;
        // console.log(addlist)
        that.setData({
            addlist: addlist
        })
    },
    itemclick(e){
        var that = this;
        // console.log(e);
        var item = e.currentTarget.dataset.item;
        var index = e.currentTarget.dataset.index;
        that.setData({
            pickitem: item,
            pickindex: index,
        })
        if (Number(item.input_type)==3){
            // 多选框
            that.setData({
                choosefalse:true,
                morekinfo: item.input_values,
            })
        }
    },
    doubleTap(){
        var that = this;
        that.setData({
            choosefalse: false,
        })
    },
    // 多选点击确定
    sureTap(){
        var that = this;
        var indec = that.data.moreindex;
        // console.log(indec)
        var pickindex = that.data.pickindex;
        var str = indec.join(',');
        var morekinfo = that.data.morekinfo;
        var addlist = that.data.addlist;
        addlist[pickindex].evalue = str;
        // addlist[pickindex].valueadd = that.data.pickitem.input_values[index].edesc;
        addlist[pickindex].input_values = morekinfo;
        var newarr = [];
        for (let i = 0, lenI = morekinfo.length; i < lenI; ++i) {
            for (let j = 0, lenJ = indec.length; j < lenJ; ++j) {
                if (Number(morekinfo[i].evalue) == Number(indec[j])) {
                    newarr.push(morekinfo[i].edesc)
                }
            }
        }
        addlist[pickindex].valueadd = newarr.join(',');
        // console.log(addlist)
        that.setData({
            choosefalse: false,
            addlist: addlist
        })
    },
    checkboxChange(e) {
        var that = this;
        // console.log('checkbox发生change事件，携带value值为：', e.detail.value)
        var indec = e.detail.value;
        const items = that.data.morekinfo;
        const values = e.detail.value;
        for (let i = 0, lenI = items.length; i < lenI; ++i) {
            items[i].checked = false;
            for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
                if (Number(items[i].evalue) == Number(values[j])) {
                    items[i].checked = true;
                    break
                }
            }
        }
        that.setData({
            morekinfo:items,
            moreindex: indec,
        })
        // console.log(items)
    },

    // 改变性别
    userSexChange: function (e) {
        this.setData({
          userSex: parseInt(e.detail.value)
        })
    },

    usertextChange: function (e) {
      this.setData({
        is_exam: parseInt(e.detail.value)
      })
  },
    // 修改用户意向等级
    userInclistchange(e){
        var that = this;
        that.setData({
          inc_index:e.detail.value
        })
    },

    uploadImage: function() {
        let that = this;
        wx.chooseImage({
            count: 1,
            sizeType: ['compressed'],
            sourceType: ['album'],
            success: function(res) {
                wx.showLoading({
                    title: '上传中~',
                })
                console.log(res);
                var photoSrc = res.tempFilePaths[0];
                share.uploadpic(photoSrc, function(res) {
                    var path = res.data.path;
                    console.log(path);
                    that.setData({
                        photo: path
                    })
                    wx.showToast({
                        title: '上传成功',
                        icon: 'none'
                    })
                    wx.hideLoading()
                }, function(res) {
                    wx.showToast({
                        title: '上传失败，请重新上传',
                        icon: 'none'
                    })
                    wx.hideLoading()
                })
            }
        })
    },
    clickpic(){
        let img=this.data.dataedit.photo?this.data.dataedit.photo:this.data.photo
        var jiaoyanCode = this.data.imgUrl+img;
        share.sendImage(jiaoyanCode);
    },


    // 选择地址
    bindMultiPickerChange: function (e) {
        // console.log(this.data.multiArray[0][this.data.multiIndex[0]]);
        // vm = this;
        this.setData({
        "multiIndex[0]": e.detail.value[0],
        "multiIndex[1]": e.detail.value[1],
        })
        this.setData({
            region: [this.data.multiArray[0][this.data.multiIndex[0]], this.data.multiArray[1][this.data.multiIndex[1]]]
        })
        // console.log(this.data.multiIndex);
        // console.log(this.data.region);
    },


    bindMultiPickerColumnChange: function (e) {
        // vm = this;
        var that = this;
        switch (e.detail.column) {
        case 0:
            list = []
            var arr = that.data.objectMultiArray[e.detail.value];
            // console.log(arr)
            for (var i = 0; i < arr.length; i++) {
            list.push(arr[i].name)
            }
            that.setData({
                "multiArray[1]": list,
                "multiIndex[0]": e.detail.value,
                "multiIndex[1]": 0,
                chooselist:arr
            })

        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
        var content = options.consultant_id;
        wx.setStorageSync('followtype',1);
        if (options.status){
            var yi_status = options.status;
        }else{
            var yi_status = 0;
        }
        if (options.isname) {
            var isname = options.isname;
        } else {
            var isname = 1;
        }
        // isname
        that.setData({
            identity: app.globalData.identity,
            adminid: app.globalData.admin_id,
            is_dl:app.globalData.is_dl,
            isname: isname,
            consultant_id: content,
            typestatus:options.type,  //1添加 2编辑
            phone:options.phone,
            yi_status: Number(yi_status),
        })
        // console.log(that.data.identity)
        // console.log(that.data.is_dl)
        if (Number(options.type)==2){
            wx.setNavigationBarTitle({
                title: '编辑资料',
            })
        }else{
            wx.setNavigationBarTitle({
                title: '添加客户',
            })
        }
        share.userInclist(function(res){
            that.setData({
                userInclist:res,  // 获取意向等级
            })
        })
        share.provinces(function(res){
            // console.log(res);
            var firarr = [],secarr=[],idfirarr=[],firall=[];
            for(var i=0;i<res.length;i++){
                firarr.push(res[i].name);
                
                var chilarr = [];
                for(var j=0;j<res[i].children.length;j++){
                if(Number(i) == 0){
                    idfirarr.push(res[i].children[j].name)
                }
                var obj = {
                    regid:i,
                    id:res[i].children[j].id,
                    name:res[i].children[j].name,
                }
                chilarr.push(obj)
                }
                secarr.push(chilarr);
            }
            firall = [firarr,idfirarr]
            that.setData({
                multiArray:firall,
                objectMultiArray:secarr,
                provinceslist:res,
                chooselist:res[0].children
            })
            // console.log(that.data.multiArray)
            // if (Number(options.type)==2){
            //     that.userInfo();
            // }else{
            that.userSubs();
            // }
        })
        
    },
    userSubs(){
        wx.showLoading({
            title: '加载中~',
        })
        var that = this;
        share.wxRequest('crmapi/user/userSubs', {}, function (res) {
            if (Number(res.data.errcode) == 0) {
                var data = res.data.data;
                // console.log(data);
                var arr = [];
                for(var i=0;i<data.lists.length;i++){
                    // if (Number(data.lists[i].input_type) >= 2){
                    data.lists[i]['valueadd'] = '请选择' + data.lists[i].title;
                    
                    var str = [{evalue:0,edesc:'请选择' + data.lists[i].title}];
                    // }
                    data.lists[i]['evalue'] = '';
                    if (Number(data.lists[i].input_type)==2){
                        // console.log(899);
                        data.lists[i].input_values = str.concat(data.lists[i].input_values)
                    } else if (Number(data.lists[i].input_type) == 3) {
                        var arr1 = data.lists[i].input_values;
                        var newarr = [];
                        for (var j = 0; j < arr1.length;j++){
                            var obj = {
                                edesc: arr1[j].edesc,
                                evalue: arr1[j].evalue,
                                checked: false,
                            }
                            newarr.push(obj)
                        }
                        data.lists[i].input_values = newarr;
                    }
                    arr.push(data.lists[i]);
                }
                // console.log(arr)
                that.setData({
                    addlist: arr,
                    // valueadd:arr
                })
                if (Number(that.data.typestatus)==2){
                    that.userInfo();
                }
            }
            wx.hideLoading()
        })
    },
    userInfo(){
        wx.showLoading({
            title: '加载中~',
        })
        var that = this;
        var formData = {
            phone:that.data.phone,	//是	string	手机号
            consultant_id:that.data.consultant_id,	//	是	string	课程顾问ID
        }
        if (Number(app.globalData.identity) == 3) {
            var url = 'crmapi/Learn/userInfo'
        }else{
            var url = 'crmapi/user/userInfo'
        }
        share.wxRequest(url,formData,function(res){
            if(Number(res.data.errcode)==0){
                var data = res.data.data.data;
                that.setData({
                    dataedit:data,
                    // is_exam:Number(data.is_test),
                    userSex:data.sex,
                    region:[data.provinces_name,data.city_name]
                })
                that.datainfo(data);
            }
            wx.hideLoading();
        })
    },

    datainfo(data){
        var that = this;
        var arr = [], arr1 = [], a = 0, b = 0;
        if (Number(data.provinces_id) > 0 || Number(data.city_id) > 0) {
            var city_id = data.city_id;
            var provinces_id = data.provinces_id;
            // multiIndex
            var provinceslist = that.data.provinceslist;
            // console.log(provinceslist)
            for (var i = 0; i < provinceslist.length; i++) {
                if (Number(provinces_id) == Number(provinceslist[i].id)) {
                    // arr = provinceslist[i].children;
                    arr = provinceslist[i].children;
                    for (var j = 0; j < provinceslist[i].children.length; j++) {
                        arr1.push(provinceslist[i].children[j].name)
                        if (Number(city_id) == Number(provinceslist[i].children[j].id)) {
                            b = j;
                        }
                    }
                    a = i;
                }
            }
            that.setData({
                chooselist: arr,
                multiIndex: [a, b],
                "multiArray[1]": arr1,
                "multiIndex[0]": a,
                "multiIndex[1]": b,
            })
        }
        that.datainfo1(data);
        
    },

    datainfo1(data){
        var that = this;
        // 意向等级
        // userInclist
        var userInclist = that.data.userInclist, inc_index = 0, name = '请选择';
        for (var i = 0; i < userInclist.length; i++) {
            if (Number(data.incl_id) == Number(userInclist[i].id)) {
                inc_index = i;
            }
        }
        // console.log(arr)
        that.setData({
            name: data.incl_name,
            inc_index: inc_index, //意向等级下标
        })

        // 自定义数据
        if (data.user_extend) {
            var user_extend = data.user_extend;
            // console.log(user_extend)
            if (user_extend != '') {
                var addlist = that.data.addlist;
                for (var i = 0; i < addlist.length; i++) {
                    var name = addlist[i].input_name;
                    var input_values = addlist[i].input_values;
                    if (Number(addlist[i].input_type) == 1) {
                        addlist[i].valueadd = user_extend[name]
                    } else if (Number(addlist[i].input_type) == 2) {
                        var uservalue = user_extend[name];
                        if (!uservalue && (uservalue == '' || Number(uservalue == 0))) {

                        } else {
                            for (var j = 0; j < input_values.length; j++) {
                                if (Number(uservalue) == Number(input_values[j].evalue)) {
                                    addlist[i].valueadd = input_values[j].edesc;
                                    addlist[i].evalue = input_values[j].evalue;
                                }
                            }
                        }
                    } else if (Number(addlist[i].input_type) == 3) {
                        var uservalue = user_extend[name];
                        if (!uservalue || (uservalue == '' || Number(uservalue == 0))) {

                        } else {
                            // var arr = uservalue.split(',');
                            var arr = uservalue;
                            // console.log(uservalue)
                            // console.log(uservalue.join(','))

                            var str = '';
                            addlist[i].evalue = uservalue.join(',');

                            for (var j = 0; j < input_values.length; j++) {
                                for (var z = 0; z < arr.length; z++) {
                                    if (Number(arr[z]) == Number(input_values[j].evalue)) {
                                        if (str == '') {
                                            str = input_values[j].edesc;
                                        } else {
                                            str = str + ',' + input_values[j].edesc;
                                        }
                                        addlist[i].input_values[j].checked = true;
                                    }
                                }
                            }
                            addlist[i].valueadd = str;
                        }
                    }
                }
                that.setData({
                    addlist: addlist,
                })
            }
        }
    },
    
  /**
   * 生命周期函数--监听页面显示
   */
    onShow: function () {
        if (wx.getStorageSync('keywordphone')) {
            wx.removeStorageSync('keywordphone');
        }
    },


    // 用户点击右上角分享
    onShareAppMessage: function () {
        return {
        title: CONFIG.SHARETITLE,
        path: CONFIG.PATHLOGIN
        }
    },

 
    // 点击提交
    submitbut: function (e) {
        var that = this;
        // console.log(e);
        var tyepsub = e.detail.target.dataset.id;  //subinfo 提交信息  licourse报课
        that.setData({
            tyepsub: tyepsub
        })
        var e1 = e.detail.value;
        // console.log(e);
        // console.log(that.data.multiIndex)
        var multiIndex = that.data.multiIndex;
        // 判断手机号 客户名称
        // else if (that.data.region[0] == '' || that.data.region[1] == '') {
        //     wx.showToast({
        //         title: '请选择地址',
        //         icon: 'none',
        //         duration: 1500
        //     })
        // } 
        var re = /^[\u4e00-\u9fa5a-z]+$/gi;//只能输入汉字和英文字母
        if (e1.truename == '') {
            wx.showToast({
                title: '请填写客户名称',
                icon: 'none',
                duration: 1500
            })
        } else if (!(/^[\u2E80-\u9FFF]+$/.test(e1.truename))) {
        // } else if (!(/^[\u4e00-\u9fa5a-z]+$/gi.test(e1.truename))){
            wx.showToast({
                title: '客户名称只能为汉字',
                icon: 'none',
                duration: 1500
            })
        } else if (Number(e1.truename.length)>5){
            wx.showToast({
                title: '客户名称最多为5个字',
                icon: 'none',
                duration: 1500
            })
        } else if (that.data.userSex==''||Number(that.data.userSex) == 0){
            wx.showToast({
                title: '请选择性别',
                icon: 'none',
                duration: 1500
            })
        }else if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(e1.tel)) || e1.tel == '') {
            wx.showToast({
                title: '请填写正确手机号',
                icon: 'none',
                duration: 1500
            })
        }
        // else if(Number(that.data.inc_index)==0){
        //     wx.showToast({
        //         title: '请选择意向等级',
        //         icon: 'none',
        //         duration: 1500
        //     })
        // } 
        else {
            
            var user_extend = {};
            var addlist = that.data.addlist;
            if (Number(addlist.length)<=0){
                var user_extend = {};
                that.addshre(user_extend, e1);
            }else{
                var a=0;
                for (var i = 0; i < addlist.length;i++){
                    var input_name = addlist[i].input_name;
                    if (Number(addlist[i].required) == 1){
                        if (Number(addlist[i].input_type==1)){
                            // 输入框
                            // console.log(e1[input_name]);
                            if (e1[input_name] == ''){
                                wx.showToast({
                                    title: '请输入' + addlist[i].title,
                                    icon: 'none',
                                    duration: 1500
                                })
                                return;
                            }else{
                                a = a + 1;
                                user_extend[input_name] = e1[input_name];
                            }
                        } else if (Number(addlist[i].input_type == 2)) {
                            if (Number(addlist[i].evalue)==0){
                                wx.showToast({
                                    title: '请选择' + addlist[i].title,
                                    icon: 'none',
                                    duration: 1500
                                })
                                return;
                            }else{
                                a = a + 1;
                                user_extend[input_name] = addlist[i].evalue;
                            }
                        } else if (Number(addlist[i].input_type == 3)) {
                            if (addlist[i].valueadd == '') {
                                wx.showToast({
                                    title: '请选择' + addlist[i].title,
                                    icon: 'none',
                                    duration: 1500
                                })
                                return;
                            } else {
                                // console.log(addlist[i].evalue);
                                a = a + 1;
                                var arr = addlist[i].evalue.split(',')
                                user_extend[input_name] = arr;
                            }
                        }
                    }else{
                        a = a+1;
                        if (Number(addlist[i].input_type == 1)) {
                            // 输入框
                            user_extend[input_name] = e1[input_name];
                        } else if (Number(addlist[i].input_type == 2)) {
                            user_extend[input_name] = addlist[i].evalue;
                        } else if (Number(addlist[i].input_type == 3)) {
                            user_extend[input_name] = addlist[i].evalue.split(',');
                        }
                    }
                }
                if (Number(a) == Number(addlist.length)){
                    that.addshre(user_extend, e1);
                }
            }
            // console.log(user_extend);
            
        }
    },
    addshre(user_extend,e1){
        var that = this;
        that.setData({
            submitfalse: false
        })
        wx.showLoading({
            title: '提交中~',
            mask: true
        })
        var multiIndex = that.data.multiIndex;
        // if (that.data.region[0] == '' || that.data.region[1] == '') {
        //     var provinces_id = ''
        //     var city_id = ''
        // } else{
        var provinces_id = that.data.provinceslist[multiIndex[0]].id
        var city_id = that.data.chooselist[multiIndex[1]].id
        // }
        var formData = {
            user_extend: JSON.stringify(user_extend),
            name: e1.truename,    //客户名称
            consultant_id: that.data.consultant_id,   //课程顾问id
            // provinces_id: provinces_id,//	是	int	省ID
            // city_id: city_id,//	是	int	市ID
            // county_id: '',//	是	int	区/县ID
            // address: e1.address,  //详细地址
            sex: that.data.userSex,  //性别 1男 2女
            note: e1.textarea,
            // email: '',
            // incl_id: that.data.userInclist[that.data.inc_index].id,  //意向等级ID
            tel:that.data.dataedit.phone
            // is_test:that.data.is_exam, //是否通过考试 1-是 2-否
            // photo:that.data.photo
        }
        // console.log(formData)
        if (Number(that.data.typestatus) == 1) {
            formData['tel'] = e1.tel;
            var is_check = that.data.is_check;  //1:可以转
            var is_cons = that.data.is_cons;  //0:没有课程顾问 1:有课程顾问 2代理商
            var is_zycon = 2;
            var is_status = that.data.is_status;
            if (Number(app.globalData.identity) == 3) {
                if (Number(that.data.share_conid)>0){
                    if (Number(is_status)==1){
                        var is_zycon = 3;
                    }else{
                        var is_zycon = 1;
                    }
                    formData['phone'] = e1.tel;
                    formData['oldPhone'] = that.data.dataedit.phone;
                    // var url = 'crmapi/user/updateUserInfo'
                    var url = ''
                    if(that.data.is_oneself==1){//已在名下，走编辑
                        url='crmapi/Learn/updateUserInfo'
                    }else{
                        url = 'crmapi/user/addusernew'
                    }
                }else{
                    var url = 'crmapi/Learn/adduser'
                }
            }else{
                if (Number(that.data.share_conid)>0){
                    if (Number(is_status)==1){
                        var is_zycon = 3;
                    }else{
                        var is_zycon = 1;
                    }
                    formData['phone'] = e1.tel;
                    formData['oldPhone'] = that.data.dataedit.phone;
                    // var url = 'crmapi/user/entryAddStuNew'
                    var url=''
                    if(that.data.is_oneself==1){//已在名下，走编辑
                        url='crmapi/user/updateUserInfo'
                    }else{
                        url = 'crmapi/user/addusernew'
                    }
                }else{
                    var url = 'crmapi/user/adduser'
                }
            }
        } 
        share.wxRequest(url, formData, function (res) {
            console.log(formData);
            wx.hideLoading();
            if (Number(res.data.errcode) == 0) {
                wx.showToast({
                    title: '成功',
                    icon: 'none'
                })
                var data = res.data.data;
                // var tyepsub = e.detail.target.dataset.id;  //subinfo 提交信息  licourse报课
                if (that.data.tyepsub == 'licourse'){
                    var is_certif = that.data.is_certif;  //0:需要认证
                    if(Number(that.data.share_conid)>0){
                        var newconid = that.data.share_conid;
                        var user_id = that.data.dataedit.user_id;
                    }else{
                        var newconid = '';
                        var user_id = res.data.user_id;
                    }
                    // console.log(user_id)
                    if (Number(is_certif)==0){
                        wx.redirectTo({
                            url: '/pages/public/identphone?user_name=' + formData.name + '&phone=' + e1.tel + '&is_certif=0&user_id=' + user_id + '&type=1&is_zycon=' + is_zycon + '&newconid=' + newconid+'',
                        })
                    }else{
                        wx.redirectTo({
                            url: '/pages/staff/choose_course?name=' + formData.name + '&tel=' + e1.tel + '&user_id=' + user_id + '&is_zycon=' + is_zycon + '&newconid=' + newconid +'&is_check='+that.data.is_check+'&is_oneself='+that.data.is_oneself,
                        })
                    }
                }else if (that.data.tyepsub == 'courselist') {
                    if(Number(that.data.share_conid)>0){
                        var newconid = that.data.share_conid;
                    }else{
                        var newconid = '';
                    }
                    wx.redirectTo({
                        url: '/pages/staff/customdetail?crm_id=' + that.data.dataedit.id + '&name=' + formData.name + '&consultant_id=' + newconid + '&newconidtype=2',
                    })
                }else{
                    setTimeout(function () {
                        wx.navigateBack();
                    }, 2000)
                }
                

            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'none',
                    duration: 2000,
                })
                that.setData({
                    submitfalse: true
                })
            }

        })
    }


})